window.ROOT = "";
(function () {
    jQuery(document).ready(function () {
        var gender=jQuery("#sex3").val();
        if(gender=="男"){
        gel("sex1").checked=true;
    }
    if(gender=="女"){
        gel("sex2").checked=true;
    }
    function gel(id) {
        return document.getElementById(id);
    }
        jQuery('.saveBtn').on('click',function() {
            var obj = document.getElementsByName("sex");
            for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    var value = obj[i].value;
                }
            }
            if (value == "male") {
                jQuery("#sex").val("男");
            }
            else if (value == "female") {
                jQuery("#sex").val("女");
            }
            var data = {
                id: jQuery('#id').val(),
                name: jQuery('#name').val(),
                sex: jQuery('#sex').val()
            };
            var url = window.rootPath + '/api/users/' + data.id;
            jQuery.ajax({
                url: encodeURI(url),
                type: 'put',
                data: JSON.stringify(data),
                dataType: 'json',
                contentType: 'application/json;charset=utf-8',
                success: function () {
                    alert("修改成功");
                }

            });

        });
});
})();